package com.yw.pms.service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yw.pms.dao.OperatorDao;
import com.yw.pms.dao.entity.Operator;
import com.yw.pms.utils.CommonResp;

@Service
public class OperatorService {
	
	private final static Logger logger = LoggerFactory.getLogger(OperatorService.class);
	
	@Resource
	private OperatorDao operatorDao;
	
	public CommonResp<String> checkLogin(HttpSession session,String loginName, String password) {
		CommonResp<String> commonResp = new CommonResp<String>();
		Operator operatorQuery = new Operator();
		operatorQuery.setLoginName(loginName);
		operatorQuery.setPassword(password);
		try {
			Operator operator = operatorDao.get(operatorQuery);
			if(operator == null){
				commonResp.fail();
				commonResp.setMsg("操作员不存在");
				return commonResp;
			}
			session.setAttribute("operator", operator);
			commonResp.success();
			logger.info("操作员【{}】登录成功",operator.getOperatorName());
		} catch (Exception e) {
			logger.error("查询操作员系统异常",e);
			commonResp.exception();
		}
		return commonResp;
	}
}
